/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package ucmconfchecker.conformance;

import java.util.Date;
import ucmconfchecker.pExecutionTrace.ExecutionTrace;

/**
 *
 * @author Administrador
 */
 /**
     * @param args the command line arguments
     */
    public class Event<T> implements Comparable{
        private Date programStart;
        private Date timeStart;
        private Long relativeTimeStart;
        private Long relativeTimeFinish;
        private Date timeFinish;
        private T event;
    private ExecutionTrace excecutionTrace;
        
        public Event(Date programStart, Date timeStart, Date timeFinish, T event){
            this.programStart = programStart;
            this.timeStart= timeStart;
            this.timeFinish = timeFinish;
            this.relativeTimeStart= timeStart.getTime()-programStart.getTime();
            this.relativeTimeFinish = timeFinish.getTime()-programStart.getTime();
            this.event = event;
        }
        public Event(Date programStart,Long timeStart, Long timeFinish, T event){
            this.programStart = programStart;
            this.timeStart= new Date(timeStart+programStart.getTime());
            this.timeFinish = new Date(timeFinish+programStart.getTime());
            this.relativeTimeStart= timeStart;
            this.relativeTimeFinish = timeFinish;
            this.event = event;
        }
        /**
         * compara con otro evento
         * @param o evento a comparar
         * @return 1 si este es precedido por el pasado por parametro
         *         0 si ambos eventos se superponen
         *        -1 si este evento precede al pasado por parametro
         */
        @Override
        public int compareTo(Object o) {
            Event other = (Event)o;
            return this.getTimeStart().compareTo(other.getTimeStart());
        }
        public int compareToStrict(Object o) {
            Event other = (Event)o;
            if(after(other)){
                return 1;   //this after other
            }else if (before(other)){
                return -1;  //other after this
            }else{
                return 0;   //this & other overlap
            }
        }
        @Override
        public String toString(){
            return "["+getEvent()+"]("+getRelativeTimeStart()+"-"+getRelativeTimeFinish()+")";
        }
        public boolean before(Event other){
            return this.getTimeFinish().compareTo(other.getTimeStart())<=0;
        }
        public boolean after(Event other){
            return this.getTimeStart().compareTo(other.getTimeFinish())>=0;
        }
        public boolean overlap(Event other){
            return !before(other) && !after(other);
        }


    public Date getTimeStart() {
        return timeStart;
    }
    public Long getRelativeTimeStart() {
        return relativeTimeStart;
    }


    public Long getRelativeTimeFinish() {
        return relativeTimeFinish;
    }

    public Date getTimeFinish() {
        return timeFinish;
    }

    public T getEvent() {
        return event;
    }

    public void addTrace(ExecutionTrace respTrace) {
        this.excecutionTrace = respTrace;
    }
    public ExecutionTrace getTrace(){
        return excecutionTrace;
    }
}